#ifndef __CHUNK_ID_HH__
#define __CHUNK_ID_HH__

#include <cstdint>
#include <glm/glm.hpp>
#include <cmath>

namespace mc
{
//! @brief 区块id
union ChunkID
{
    uint64_t id;
    glm::ivec2 coord;
    ChunkID(int x, int y) : coord(glm::ivec2(x, y)) {}
    ChunkID(const ChunkID&) = default;

    //! @brief 运算符重载
    bool operator == (const ChunkID& c2) const
    { return this->id == c2.id; }

    bool operator != (const ChunkID& c2) const
    { return this->id != c2.id; }

    bool operator > (const ChunkID& c2) const
    { return this->id > c2.id; }

    bool operator < (const ChunkID& c2) const
    { return this->id < c2.id; }

    static float distance(const ChunkID& c1, const ChunkID& c2)
    { return sqrt( pow(c1.coord.x - c2.coord.x, 2) + pow(c1.coord.y - c2.coord.y, 2) ); }

    static unsigned int interval(const ChunkID& c1, const ChunkID& c2)
    {
        unsigned int deltaX = abs(c1.coord.x - c2.coord.x);
        unsigned int deltaZ = abs(c1.coord.y - c2.coord.y);
        return deltaX > deltaZ ? deltaX : deltaZ;
    }
};

class Chunk;

struct ChunkMsg
{
    uint64_t index;
    Chunk* chunk;
    ChunkMsg(uint64_t i, Chunk* c):
        index(i), chunk(c) {}
    ChunkMsg() : index(0), chunk(nullptr) {}
};

}

#endif